import { Module } from '@nestjs/common'
import { AuthService } from './auth.service'
import { AuthController } from './auth.controller'
import { UserModule } from '../user/user.module'
import { PassportModule } from '@nestjs/passport'
import { LocalStrategy } from './local.strategy'
import { JwtStrategy } from './jwt.strategy'
import { RedisModule } from 'src/redis/redis.module'
import { JwtModule } from '@nestjs/jwt'
import { ConfigService } from '@nestjs/config'
import { MenuModule } from '../menu/menu.module';
import { RoleModule } from 'src/role/role.module';

const jwtModule = JwtModule.registerAsync({
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => {
    return {
      secret: configService.get('JWT_SECRET', 'test123456'),
      signOptions: {
        expiresIn: configService.get<string>('JWT_EXPIRATION_TIME', '4h')
        //全局配置的过期时间   jwtService.sign() 方法内直接指定 expiresIn 来覆盖全局配置的过期时间
      }
    }
  }
})

@Module({
  imports: [UserModule, MenuModule, RoleModule, PassportModule, RedisModule, jwtModule],
  controllers: [AuthController],
  providers: [AuthService, LocalStrategy, JwtStrategy],
  exports: [AuthService]
})
export class AuthModule { }
